package org.celery.modules.shop.wrapper;

import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.utils.BeanUtil;
import org.celery.modules.shop.entity.Shop;
import org.celery.modules.shop.vo.ShopVO;
import org.springblade.core.tool.utils.Func;

/**
 * 店铺表包装类,返回视图层所需的字段
 *
 * @author Celery
 * @since 2023-06-12
 */
public class ShopWrapper extends BaseEntityWrapper<Shop, ShopVO>  {

    public static ShopWrapper build() {
        return new ShopWrapper();
    }

	@Override
	public ShopVO entityVO(Shop shop) {
		ShopVO shopVO = BeanUtil.copy(shop, ShopVO.class);

		BladeUser bladeUser = SecureUtil.getUser();
		if (Func.isNotEmpty(bladeUser) && (bladeUser.getRoleName().equals("yunying") || bladeUser.getRoleName().equals("customer"))) {
			ShopVO tmpVo = shopVO;
			shopVO = new ShopVO();
			shopVO.setId(tmpVo.getId());
			shopVO.setResourceOwner(tmpVo.getResourceOwner());
			shopVO.setBusinessLicense(tmpVo.getBusinessLicense());
			shopVO.setStatus(tmpVo.getStatus());
			shopVO.setIsHideInfo(true);
		} else {
			shopVO.setIsHideInfo(false);
		}

		return shopVO;
	}

}
